package com.xiaobu.shop.controller;


import com.xiaobu.shop.domain.ResponseResult;
import com.xiaobu.shop.domain.entity.ShopUser;
import com.xiaobu.shop.service.ShopUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaobu
 * @since 2023/06/16
 */
@RestController
@RequestMapping("/shop/user")
public class ShopUserController {

    @Autowired
    ShopUserService shopUserService;
    @RequestMapping("/login")
    public ResponseResult login(@RequestBody ShopUser shopUser){
        return shopUserService.login(shopUser);
    }

    @RequestMapping("/register")
    public ResponseResult register(@RequestBody ShopUser shopUser){
        return shopUserService.register(shopUser);
    }

    @RequestMapping("/getUserDetail")
    public ResponseResult getUserDetail(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        ShopUser user = (ShopUser)authentication.getPrincipal();
        user.setPassword(null);
        ResponseResult responseResult=new ResponseResult(200,"获取成功",user);
        return responseResult;
    }
    
}

